#pragma once
#ifndef __CMQTTCLIENT__H
#define __CMQTTCLIENT__H

#include "MQTTClient.h"
#include <string>

typedef void(*connectionLostCB)(void* context, char* cause);
typedef int(*messageArrivedCB)(void* context, char* topicName, int topicLen, MQTTClient_message* message);
typedef void(*deliveryCompCB)(void* context, MQTTClient_deliveryToken dt);

enum {
	PUBLISH = 0,
	SUBSCRIBE
};

typedef struct {
	int type;
	int keepAliveInterval;
	int cleanSession;
	int qos;
	int timeout;

	std::string address;
	std::string clientID;
	std::string topic;

	//MQTTClient_connectionLost connlostCB;
	//MQTTClient_messageArrived msgCB;
	// MQTTClient_deliveryComplete;
	connectionLostCB connlostCB;
	messageArrivedCB msgCB;
	deliveryCompCB deliverycompleteCB;

	void* context;
}MQTTConf;

class CMQTTClent {

public:
	CMQTTClent();
	~CMQTTClent();
	void init();
	void startSub();
	void publish(char* data, int len, int retained);
	void mqttDestory();
	int reconnect();

public:
	MQTTConf conf;
private:
	MQTTClient client;
	MQTTClient_connectOptions conn_opts;
	MQTTClient_message msg;
	MQTTClient_deliveryToken token;
	int rc;
};

#endif // !__CMQTTCLIENT__H
